package com.sjp.config;

import com.sjp.interceptor.MyInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyWebMvcConfig implements WebMvcConfigurer {

    @Autowired
    MyInterceptor myInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 配置拦截器
        registry.addInterceptor(myInterceptor).addPathPatterns("/admin/**").excludePathPatterns("/admin/login").excludePathPatterns("/admin/checkLogin").excludePathPatterns("/admin/img/**");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 配置虚拟映射路径，访问 /upload/xxx 即访问 E:/自写项目/administrator-demo/src/main/resources/static/admin/img/upload/xxx
        registry.addResourceHandler("/upload/**").addResourceLocations("file:E:/自写项目/administrator-demo/src/main/resources/static/admin/img/upload/");
    }
}
